package com.dhcc.cdc.io.adm;

import com.dhcc.cdc.busi.dao.CdcOrdexecMapper;
import com.dhcc.cdc.busi.dao.CdcOrdmastMapper;
import com.dhcc.cdc.busi.entity.CdcOrdexecEntity;
import com.dhcc.cdc.busi.entity.CdcOrdmastEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CdcOrderData {

    @Autowired
    private CdcOrdexecMapper ordExecMapper;
    @Autowired
    private CdcOrdmastMapper ordMastMapper;

    public CdcOrdexecEntity getEntity(Long episodeId, String orderCode) {
        CdcOrdmastEntity tmpOrdmast = new CdcOrdmastEntity();
        tmpOrdmast.setCode(orderCode);
        CdcOrdmastEntity Ordmast = ordMastMapper.selectOne(tmpOrdmast);
        Long ordmastId = Ordmast.getId();

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("episode_id", episodeId);
        map.put("order_mast_id", ordmastId);
        List<CdcOrdexecEntity> ordexec = ordExecMapper.selectByMap(map);
        if (ordexec.size()<1) {
            return null;
        }
        return ordexec.get(0);
    }

    // 取执行时间
    public Date getOrdexecTime(String episodeId, String orderCode) {
        Long l_episodeId=Long.valueOf(episodeId);
        CdcOrdexecEntity ordExec=null;
        
        ordExec = getEntity(l_episodeId, orderCode);
        if (ordExec != null) {
            return ordExec.getStartDate();
        }
        
        return null;
    }
}
